//
//  FCVehicleIolAndCurveOptionTableView.m
//  ZhuKuang
//
//  Created by mafy on 17/7/12.
//  Copyright © 2017年 jjkj. All rights reserved.
//

#import "FCVehicleIolAndCurveOptionTableView.h"
#import "FCVehicleIolAndCurveModel.h"

@interface FCVehicleIolAndCurveOptionTableView()<UITableViewDelegate,UITableViewDataSource>

@end

@implementation FCVehicleIolAndCurveOptionTableView

- (void)setType:(NSString *)type{
    _type = type;
    //1 部门 2 车辆
}

- (void)setDataArray:(NSArray *)dataArray{
    _dataArray = dataArray;
    
    [self reloadData];
}

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style{
    
    self = [super initWithFrame:frame style:style];
    
    if (self) {
        
        self.delegate = self;
        self.dataSource = self;
//        self.separatorInset = UIEdgeInsetsMake(0,0,0,0);//top left bottom right 左右边距相同
//        self.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
        self.separatorStyle = UITableViewCellSelectionStyleNone;
        self.showsHorizontalScrollIndicator = NO;
        self.showsVerticalScrollIndicator = NO;
    }
    
    return self;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 44;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *identifier = @"cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    
    if (!cell) {
        
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    
    if ([self.type isEqualToString:@"1"]) {
        
        FCVehicleIolAndCurveModel *model = self.dataArray[indexPath.row];
        
        cell.textLabel.text = model.name;
    }
    else if ([self.type isEqualToString:@"2"]){
        
        FCVehicleIolAndCurveModel *model = self.dataArray[indexPath.row];
        
        cell.textLabel.text = model.CarNo;
    }
    else if ([self.type isEqualToString:@"3"]){
        
        cell.textLabel.text = self.dataArray[indexPath.row];
    }
    
    cell.textLabel.textAlignment = NSTextAlignmentCenter;
    cell.textLabel.textColor = COLOR(13, 169, 215, 1);
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString *paramID = @"选择车辆部门";
    NSString *paramName = @"选择车辆";
    
    if ([self.type isEqualToString:@"1"]) {
        
        FCVehicleIolAndCurveModel *model = self.dataArray[indexPath.row];
        
        paramID = model.carShopId;//部门ID
        paramName = model.name;
    }
    else if ([self.type isEqualToString:@"2"]){
        
        FCVehicleIolAndCurveModel *model = self.dataArray[indexPath.row];
        
        paramID = model.CarID;//车辆ID
        paramName = model.CarNo;
    }
    else if ([self.type isEqualToString:@"3"]){
        
        paramID = @"";
        paramName = self.dataArray[indexPath.row];
    }
    
    if (_selectedCompletionHandle) {
        
        _selectedCompletionHandle(self.type, paramID, paramName);
    }
}


@end
